package com.xc.freeapp.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2016/8/9.
 */
@WebFilter(urlPatterns = "/*")
@Slf4j
public class HttpFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        log.info("进入过滤器1111");

        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
//		httpServletResponse.setHeader("Content-Type",
//				"application/json;charset=UTF-8");
        httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
        httpServletResponse.setHeader("Access-Control-Allow-Methods",
                "POST, PUT, GET, DELETE, OPTIONS"); // will need to enable other
        // methods when/as
        // implemented
        httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
        httpServletResponse
                .setHeader(
                        "Access-Control-Allow-Headers",
                        "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With,AuthInfo");
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
